package cn.tedu.lbs.article.web.controller;

import cn.tedu.lbs.article.web.service.ArticleService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.content.param.ArticleContentParam;
import com.tarena.lbs.pojo.content.query.ArticleQuery;
import com.tarena.lbs.pojo.content.vo.ArticleVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
@Slf4j
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    //前后台查询文章分页列表
    @GetMapping("/admin/content/article/list")
    public Result<PageResult<ArticleVO>> pageList(ArticleQuery articleQuery)
        throws BusinessException {
        return new Result<>(articleService.pageList(articleQuery));
    }
    //文章推文创作 表单提交 后台新增 小程序前台笔记发布 同一个接口
    @PostMapping("/admin/content/article/insert")
    public Result<Void> save(ArticleContentParam articleContentParam)
        throws BusinessException{
        articleService.save(articleContentParam);
        return Result.success();
    }
    //前台查询文章 统计文章标签功能
    @GetMapping("/admin/content/article/getArticleLabel")
    public Result<Set<String>> getArticleLabels(ArticleQuery articleQuery)
        throws BusinessException{
        log.info("搜索标签集合入参:{}",articleQuery);
        return new Result<>(articleService.getArticleLabels(articleQuery));
    }
    //查询文章详情
    @GetMapping("/admin/content/article/get")
    public Result<ArticleVO> detail(Integer id)throws BusinessException{
        return new Result<>(articleService.detail(id));
    }

}
